package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.mapper.FlowChartImgMapper;
import com.ruoyi.system.mapper.FlowChartMapper;
import com.ruoyi.system.mapper.FlowChartNodeMapper;
import com.ruoyi.system.mapper.PersonnelInformationUserMapper;
import com.ruoyi.system.service.FlowChartService;
import com.ruoyi.system.service.PersonnelInformationUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户 业务层处理
 * 
 * @author ruoyi
 */
@Service
public class FlowChartImpl implements FlowChartService
{
    private static final Logger log = LoggerFactory.getLogger(FlowChartImpl.class);

    @Autowired
    private FlowChartMapper flowChartMapper;
    @Autowired
    private FlowChartNodeMapper flowChartNodeMapper;
    @Autowired
    private FlowChartImgMapper flowChartImgMapper;


    @Override
    public List<FlowChart> selectFileDataList(FlowChartMenus fileData) {
        List<String> list = new ArrayList<>();
        String menus = fileData.getMenus();
        if(StringUtils.isNoneBlank(menus)) {
            if (menus.indexOf(",") != -1) {
                String[] split = menus.split(",");

                for (int i = 0; i < split.length; i++) {
                    String s = split[i];
                    list.add(s);
                }

            }else{
                list.add(menus);
            }
            fileData.setListmenus(list);
        }


        return flowChartMapper.selectFileDataList(fileData);
    }
    @Override
    public List<FlowChart> selectlistAfterList(FlowChartMenus fileData) {
        String menus = fileData.getMenus();
        if(StringUtils.isNoneBlank(menus)) {
            List<String> list = new ArrayList<>();
            if (menus.indexOf(",") != -1) {
                String[] split = menus.split(",");

                for (int i = 0; i < split.length; i++) {
                    String s = split[i];
                    list.add(s);
                }

            }else{
                list.add(menus);
            }
            fileData.setListmenus(list);
        }

        return flowChartMapper.selectlistAfterList(fileData);
    }
    @Override
    public List<FlowChart> selectlistTemporaryStorage(FlowChartMenus fileData) {
        String menus = fileData.getMenus();
        if(StringUtils.isNoneBlank(menus)) {
            List<String> list = new ArrayList<>();
            if(menus.indexOf(",")!=-1) {
                String[] split = menus.split(",");

                for (int i = 0; i < split.length; i++) {
                    String s = split[i];
                    list.add(s);
                }
            }else{
                list.add(menus);
            }
            fileData.setListmenus(list);
        }
        return flowChartMapper.selectlistTemporaryStorage(fileData);
    }

    @Override
    public void updatefinish(Long id) {
        FlowChart flowChar = flowChartMapper.getFlowCharIdObj(id);
        flowChartMapper.insertFlowChartVm(flowChar);
        flowChartMapper.updatefinish(id);
    }

    @Override
    public int addModalNode(FlowChartNode flowchartNode) {
        return flowChartNodeMapper.insert(flowchartNode);
    }

    /**
     *描述 ：流程图详情
     *@author senyuan.li
     *@date 18:15 2024/4/14
     *@param [id]
     *@return void
     **/

    @Override
    public FlowChartVm getModalNode(Long id) {
        FlowChartVm flowchart=flowChartMapper.getFlowCharId(id);
        List<FlowChartNode> list1=flowChartNodeMapper.getNodeId(id);
        flowchart.setFlowChartNode(list1);
                return flowchart;
    }

    @Override
    public List<FlowChartNode> getNodeId(Long id) {
        return  flowChartNodeMapper.getNodeId(id);
    }

    @Override
    public int updateModalNode(FlowChartNode flowchartNode) {
        return flowChartNodeMapper.updateModalNode(flowchartNode);
    }

    @Override
    public FlowChartNode getNdesName(FlowChartNode flowchartNode) {
        return flowChartNodeMapper.getNdesName(flowchartNode);
    }

    @Override
    public int updateModalNodeOperationType(FlowChartNode flowchartNode) {
        return flowChartNodeMapper.updateModalNodeOperationType(flowchartNode);
    }

    @Override
    public int updateNotifyPerson(FlowChart flowChart) {
        return flowChartMapper.updateNotifyPerson(flowChart);
    }

    @Override
    public FlowChartNode getflowChartNode(int pid, String nodesId) {
        return flowChartMapper.getflowChartNode(pid,nodesId);
    }

    @Override
    public int insertFileData(FlowChart personnelInformationUser) {
          return flowChartMapper.insert(personnelInformationUser);
    }

    @Override
    public int deleteUserByIds(Integer id) {
        return flowChartMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int editSave(FlowChart personnelInformationUser) {
        return 0;
    }

    @Override
    public void insertFileImg(String s, Integer id) {
        flowChartImgMapper.insertFileImg(s,id);
    }


}
